package com.kenliang.javase.concurrent;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author KenLiang
 * @description:
 * @date Created in 5:00 PM 2020/5/24.
 */
public class AtomicReferenceTest {
    public static void main(String[] args) {
        Person p1 =  new Person("p1");
        Person p2 =  new Person("p2");
//        p1.setName("p11");
        AtomicReference ar = new AtomicReference(p1);
        //检查对象的引用指针
        boolean b = ar.compareAndSet(p1, p2);
        if(b){
            System.out.println("success----"+((Person)ar.get()).getName());

        }else{
            System.out.println("fial----"+((Person)ar.get()).getName());
        }


    }

}
class Person{
    private String name;
    public Person(String name){
        this.name=name;
    }
    public void setName(String name){
        this.name=name;
    }
    public String getName(){
        return this.name;
    }
}